package com.mzp.XbShop.controller;

import com.alipay.api.AlipayApiException;
import com.mzp.XbShop.Vo.AliPayVo;
import com.mzp.XbShop.common.entity.Result;
import com.mzp.XbShop.common.entity.StatusCode;
import com.mzp.XbShop.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;

@RestController
@CrossOrigin
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private PayService payService;

    /**
     * 下单支付
     */
    @RequestMapping("/AliPay")
    public Object pay(@RequestBody AliPayVo aliPayVo) throws AlipayApiException {
        Date date = new Date();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd HHmmss");
        //转换格式为yyyyMMdd
        String Out_trade_no = dateFormat.format(date);
        //根据时间设置唯一订单号，精确到秒
        aliPayVo.setOut_trade_no(Out_trade_no);

        System.out.println("执行了支付");
        return payService.AliPay(aliPayVo);
    }

}
